/**
 * Copyright (c) 2014-2015, Suredy technology Co., Ltd. All rights reserved.
 * @author ZhangMaoren 
 * @since 2015年6月26日
 * @version 0.1
 */
package com.suredy.base.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.suredy.core.model.BaseModel;




/**
 * @author ZhangMaoren
 *
 */
@Entity
@Table(name = "T_MENU")
public class Menu extends BaseModel {


	/**
	 * 
	 */
	private static final long serialVersionUID = -8365810619847576336L;

	@Column(name = "URL", nullable = false)
	private String url;

	@Column(name = "NAME", nullable = false)
	private String text;
	
	@Column(name = "RESOURCEID")
	private String resourceId;

	@Column(name = "SORT", columnDefinition = "int default 0", nullable = false)
	private Integer sort;
	
	@Column(name = "ICON")
	private String icon;
	
	@Column(name = "ACTIVE")
	private Boolean active;
	
	@Column(name = "COLLAPSE")
	private Boolean collapse;
	


	@JsonIgnore
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	@JoinColumn(name = "PARENTID")
	private Menu parent;

	@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@OrderBy("sort")
	@Fetch(FetchMode.SUBSELECT)
	private List<Menu> children;

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getText() {
		return text;
	}

	public void setText(String name) {
		this.text = name;
	}

	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}


	public Menu getParent() {
		return parent;
	}

	public void setParent(Menu parent) {
		this.parent = parent;
	}
	
	
	/**
	 * @return the resourceUri
	 */
	public String getResourceId() {
		return resourceId;
	}

	
	/**
	 * @param resourceId the resourceId to set
	 */
	public void setResourceId(String resourceId) {
		this.resourceId = resourceId;
	}
	
	

	
	/**
	 * @return the icon
	 */
	public String getIcon() {
		return icon;
	}

	
	/**
	 * @param icon the icon to set
	 */
	public void setIcon(String icon) {
		this.icon = icon;
	}

	
	/**
	 * @return the isActive
	 */
	public Boolean getActive() {
		return active;
	}

	
	/**
	 * @param active the isActive to set
	 */
	public void setActive(Boolean active) {
		this.active = active;
	}

	
	/**
	 * @return the isCollapsed
	 */
	public Boolean getCollapse() {
		return collapse;
	}

	
	/**
	 * @param collapse the isCollapsed to set
	 */
	public void setCollapse(Boolean collapse) {
		this.collapse = collapse;
	}

	public List<Menu> getChildren() {
		return children;
	}

	public void setChildren(List<Menu> children) {
		this.children = children;
	}
}
